﻿using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.BandedGrid;
using DevExpress.XtraGrid.Views.Base;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Const;
using RecruitStudents.Utility.Helper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RecruitStudents.Client.Examinee
{

    public partial class Examinee_ScoreSearchForm_List : BaseForm
    {

        BLL.ServiceComm serviceComm = new BLL.ServiceComm();
        BLL.ServiceExaminee serviceExam = new BLL.ServiceExaminee();
        public Examinee_ScoreSearchForm_List()
        {
            InitializeComponent();
            InitData();
        }


        #region 初始页面
        private void InitData()
        {
            #region 绑定考点列表
            DataTable dtExamCity = serviceComm.GetExamPlaceTable();
            DataRow dr = dtExamCity.NewRow();
            dr["ExamPlaceNO"] = "";
            dr["ExamPlaceName"] = "";
            dtExamCity.Rows.InsertAt(dr, 0);

            txtExamCity.Properties.DataSource = dtExamCity;
            txtExamCity.Properties.Columns.Clear();
            txtExamCity.Properties.Columns.Add(new LookUpColumnInfo("ExamPlaceNO", 30, "考点代码"));
            txtExamCity.Properties.Columns.Add(new LookUpColumnInfo("ExamPlaceName", 55, "考点名称"));
            txtExamCity.Properties.ValueMember = "ExamPlaceNO";
            txtExamCity.Properties.DisplayMember = "ExamPlaceName";
            txtExamCity.Properties.NullText = "";
            txtExamCity.EditValue = string.IsNullOrEmpty(SessionerHelper.ExamPlaceID) ? "310000" : SessionerHelper.ExamPlaceID;
            //txtExamCity.EditValue = strExamCity;
            #endregion

            #region 绑定专业
            DataTable dtSpecialityKinds = new DataTable();
            dtSpecialityKinds.Columns.Add("SpecialityKindsNO");
            dtSpecialityKinds.Columns.Add("SpecialityKindsName");
            dtSpecialityKinds.Rows.Add(new object[] { "1303010", "表演" });
            dtSpecialityKinds.Rows.Add(new object[] { "1303090", "播音" });


            //dtSpecialityKinds.Rows.Add(new object[] { "'1303010_A','1303010_B','1303010_C','1303010_D'", "表演" });
            //dtSpecialityKinds.Rows.Add(new object[] { "'1303090_A','1303090_B','1303090_C','1303090_D'", "播音" });

            //dtSpecialityKinds.Rows.Add(new object[] { "'130301A','130301B','130301C','130301D'", "表演" });
            //dtSpecialityKinds.Rows.Add(new object[] { "'130309A','130309B','130309C','130309D'", "播音" });


            //DataTable dtSpecialityKinds = serviceComm.GetSpecialityKindsTable(SessionerHelper.SystemYear);
            //DataRow drpecialityKinds = dtSpecialityKinds.NewRow();
            //drpecialityKinds["SpecialityKindsNO"] = "";
            //drpecialityKinds["SpecialityKindsName"] = "";
            //dtSpecialityKinds.Rows.InsertAt(drpecialityKinds, 0);
            comboSpecialityKindsNO.Properties.DataSource = dtSpecialityKinds;
            comboSpecialityKindsNO.Properties.Columns.Clear();
            comboSpecialityKindsNO.Properties.Columns.Add(new LookUpColumnInfo("SpecialityKindsNO", 30, "专业代码"));
            comboSpecialityKindsNO.Properties.Columns.Add(new LookUpColumnInfo("SpecialityKindsName", 55, "专业名称"));
            comboSpecialityKindsNO.Properties.ValueMember = "SpecialityKindsNO";
            comboSpecialityKindsNO.Properties.DisplayMember = "SpecialityKindsName";
            comboSpecialityKindsNO.Properties.NullText = "";
            comboSpecialityKindsNO.Properties.Columns[0].Visible = false;
            #endregion

            BindAppointmentGroup("", "", ""); //绑定考试分组
        }
        #endregion

        #region 绑定考试分组
        private void BindAppointmentGroup(string queryExamCity, string querySpecialityKindsNO, string queryExamLevel)
        {
            comboExamRoom.Properties.DataSource = null;
            comboExamRoom.Properties.NullText = "";
            comboExamRoom.EditValue = null;
            string ExamPlaceID = string.Empty;
            string ExamPlaceName = string.Empty;
            if (txtExamCity.EditValue != null)
            {
                ExamPlaceID = txtExamCity.EditValue.ToSafeString();
            }
            string SpecialityKindsNO = string.Empty;
            if (comboSpecialityKindsNO.EditValue != null)
            {
                SpecialityKindsNO = comboSpecialityKindsNO.EditValue.ToSafeString();
            }
            string ExamLevel = "1";
            if (ExamPlaceID.IsNullOrEmptyString() || SpecialityKindsNO.IsNullOrEmptyString() || ExamLevel.IsNullOrEmptyString())
            {
                return;
            }
            using (DataTable dt = serviceComm.GetExamRoomByPlaceID_Speciality_Level_CS(ExamPlaceID, SpecialityKindsNO, ExamLevel))
            {
                comboExamRoom.Properties.DataSource = dt;
                comboExamRoom.Properties.Columns.Clear();
                comboExamRoom.Properties.Columns.Add(new LookUpColumnInfo("ExamRoomNO", 30, "考场编号"));
                comboExamRoom.Properties.Columns.Add(new LookUpColumnInfo("ExamRoomName", 55, "考场名称"));
                comboExamRoom.Properties.ValueMember = "ExamRoomNO";
                comboExamRoom.Properties.DisplayMember = "ExamRoomName";
                comboExamRoom.Properties.NullText = "";
            }
        }
        #endregion

        #region 下拉框选择事件
        private void txtExamCity_EditValueChanged(object sender, EventArgs e)
        {
            BindAppointmentGroup("", "", ""); //绑定考试分组
            //if (txtExamCity.Text != "" && comboSpecialityKindsNO.Text != "" && comboExamLevel.Text != "")
            //{
            //    BindAppointmentGroup(txtExamCity.EditValue.ToString(), comboSpecialityKindsNO.EditValue.ToString(), comboExamLevel.EditValue.ToString());
            //}
        }

        private void comboSpecialityKindsNO_EditValueChanged(object sender, EventArgs e)
        {
            BindAppointmentGroup("", "", ""); //绑定考试分组
            //if (txtExamCity.Text != "" && comboSpecialityKindsNO.Text != "" && comboExamLevel.Text != "")
            //{
            //    BindAppointmentGroup(txtExamCity.EditValue.ToString(), comboSpecialityKindsNO.EditValue.ToString(), comboExamLevel.EditValue.ToString());
            //}
        }

        private void comboExamLevel_EditValueChanged(object sender, EventArgs e)
        {
            BindAppointmentGroup("", "", ""); //绑定考试分组
            //if (txtExamCity.Text != "" && comboSpecialityKindsNO.Text != "" && comboExamLevel.Text != "")
            //{
            //    BindAppointmentGroup(txtExamCity.EditValue.ToString(), comboSpecialityKindsNO.EditValue.ToString(), comboExamLevel.EditValue.ToString());
            //}
        }
        #endregion



        private void btnQuery_Click(object sender, EventArgs e)
        {
            DataTable dt1 = serviceExam.GetExamineeScoreSearchForm1(txtExamCity.EditValue.ToSafeString(), comboSpecialityKindsNO.EditValue.ToSafeString(),
              "1", txtName.Text, txtIdCard.Text, txtNMT_SignUpID.Text, comboExamRoom.EditValue.ToSafeString(), SessionerHelper.SystemYear, 
              txtStartDate.Text, txtEndDate.Text,txtAllowExamID1.Text);
            gridControl1.DataSource = dt1;


            DataTable dt2 = serviceExam.GetExamineeScoreSearchForm2(txtExamCity.EditValue.ToSafeString(), comboSpecialityKindsNO.EditValue.ToSafeString(),
              "1", txtName.Text, txtIdCard.Text, txtNMT_SignUpID.Text, comboExamRoom.EditValue.ToSafeString(), SessionerHelper.SystemYear,
              txtStartDate.Text, txtEndDate.Text, txtAllowExamID1.Text);
            gridControl2.DataSource = dt2;


            DataTable dt3 = serviceExam.GetExamineeScoreSearchForm3(txtExamCity.EditValue.ToSafeString(), comboSpecialityKindsNO.EditValue.ToSafeString(),
              "1", txtName.Text, txtIdCard.Text, txtNMT_SignUpID.Text, comboExamRoom.EditValue.ToSafeString(), SessionerHelper.SystemYear, 
              txtStartDate.Text, txtEndDate.Text, txtAllowExamID1.Text);
            gridControl3.DataSource = dt3;







            btnImportExcel.Enabled = true;
        }

        private void btnImportExcel_Click(object sender, EventArgs e)
        {
            Examinee_ScoreSearchForm_Export_List export = new Examinee_ScoreSearchForm_Export_List();
            export.ShowDialog();
            //if (comboExamRoom.EditValue == null || comboExamRoom.EditValue.ToSafeString() == "")
            //{
            //    DevHelper.ShowErrorMessageBox("请先选择考场进行导出!");
            //    return;
            //}
            //DataSet ds = serviceExam.GetExamineeScoreSearchFormExcel(txtExamCity.EditValue.ToSafeString(), comboSpecialityKindsNO.EditValue.ToSafeString(),
            //  "1", txtName.Text, txtIdCard.Text, txtNMT_SignUpID.Text, comboExamRoom.EditValue.ToSafeString(), SessionerHelper.SystemYear, txtStartDate.Text, txtEndDate.Text);

            //if (ds.Tables.Count == 0)
            //{

            //    //string str = "      评委：肖英          考场： 红楼102          打印时间:2015/12/20 11:26:31";

            //    DevHelper.ShowErrorMessageBox("您选择的考场没有进行考生考试!");
            //    return;
            //}

            //try
            //{

            //    SaveFileDialog kk = new SaveFileDialog();
            //    kk.Title = "保存EXECL文件";
            //    kk.Filter = "EXECL文件(*.xls) |*.xls |所有文件(*.*) |*.*";
            //    kk.FilterIndex = 1;
            //    kk.FileName = txtExamCity.Text + comboSpecialityKindsNO.Text + comboExamRoom.Text + "考生打分表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
            //    kk.ShowDialog();
            //    if (kk.FileName.IndexOf(":") < 0) return; //被点了取消 

            //    string saveFileName = kk.FileName;

            //    NPOIHelper.ExportExcel(ds, saveFileName);
            //}
            //catch (Exception ex)
            //{

            //}

        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Dispose();
            this.Close();
        }
    }
}
